package com.example.demo.day0301;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.InputStreamReader;

public class DemoOver {
    public static void main(String[] args) {
        try {
            DemoOver.testDemoSyetemIn1();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public  static void testDemoSyetemIn1() throws Exception {
    InputStreamReader is = new InputStreamReader(System.in);
    //创建一个键盘输入数据的输入流
    BufferedReader br = new BufferedReader(is);
    //把输入流放入缓冲流中
    BufferedWriter out = new BufferedWriter(new FileWriter("D:\\demo\\src\\main\\java\\com\\example\\demo\\day0301\\tt6.txt"));
    //创建一个字符输出流的对象并放在缓冲字符输出流中
    String string = "";//定义一个临时接受数据的字符串
    while((string = br.readLine()) != null){
        if (string.equals("over")){//读取文件直到字符串"over"
            break;//中断循环
        }
        out.write(string);//将字符串写入内存
    }
    out.flush();//将数据从内存刷至硬盘上
    out.close();
    br.close();
    is.close();//先开后关
    }
}
